from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
from postion import options
from postion import service

driver = webdriver.Chrome(options=options,service=service)
driver.get(r'https://www.baidu.com/')
sleep(3)
driver.find_element(By.LINK_TEXT, 'hao123').click()
sleep(3)

# 先关闭 hao123 页面，再关闭 baidu 页面
hao123_handle = driver.window_handles[1]
driver.switch_to.window(hao123_handle)  # 切换到指定页
driver.close()#关闭窗口
sleep(3)
driver.quit()